const storageDao = require('../dao/storageDao');

const storageService = {
    async setItem(uid, key, value) {
        let result;
        try {
            result = await storageDao.setItem(uid, key, value);
            result = { code: 200, message: 'success', data: null };
        } catch (err) {
            result = { code: 500, message: 'error', data: null };
        }
        return result;
    },
    async getItem(uid, key) {
        let result;
        try {
            result = await storageDao.getItem(uid, key);
            if (result.length > 0) {
                result = { code: 200, message: 'success', data: result[0] };
            } else {
                result = { code: 200, message: 'error', data: null };
            }
        } catch (err) {
            result = { code: 500, message: 'error', data: null };
        }
        return result;
    },
    async removeItem(uid, key) {
        let result;
        try {
            result = await storageDao.removeItem(uid, key);
            result = { code: 200, message: 'success', data: null };
        } catch (err) {
            result = { code: 500, message: 'error', data: null };
        }
        return result;
    },
};

module.exports = storageService;